home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / selectdata.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  6KB  |  217 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. enum {
  34.     SELECT_CANCEL,
  35.     SELECT_OKAY,
  36.     SELECT_SELECTBASE,
  37.     SELECT_SELECTTYPE};
  38.  
  39. static char sel_patternbuf[80];
  40.  
  41. struct RequesterBase select_req={
  42.     36,3,50,27,
  43.     8,6,
  44.     0,0,0,0,NULL,NULL,NULL,NULL,
  45.     NULL,NULL,NULL,
  46.     0,0,NULL,0,NULL};
  47.  
  48. struct TagItem
  49.     select_base_gadget[]={
  50.         {RO_Type,OBJECT_GADGET},
  51.         {RO_GadgetType,GADGET_CYCLE},
  52.         {RO_GadgetID,SELECT_SELECTBASE},
  53.         {RO_Top,1},
  54.         {RO_TopFine,2},
  55.         {RO_Width,6},
  56.         {RO_WidthFine,24},
  57.         {RO_Height,1},
  58.         {RO_HeightFine,6},
  59.         {RO_HighRecess,TRUE},
  60.         {TAG_END,0}},
  61.     select_pattern_gadget[]={
  62.         {RO_Type,OBJECT_GADGET},
  63.         {RO_GadgetType,GADGET_STRING},
  64.         {RO_GadgetID,SELECT_OKAY},
  65.         {RO_Top,1},
  66.         {RO_TopFine,4},
  67.         {RO_Height,1},
  68.         {RO_HeightFine,2},
  69.         {RO_Left,6},
  70.         {RO_LeftFine,30},
  71.         {RO_Width,30},
  72.         {RO_StringBuf,(ULONG)sel_patternbuf},
  73.         {RO_StringLen,79},
  74.         {RO_StringUndo,(ULONG)str_undobuffer},
  75.         {TAG_END,0}},
  76.  
  77.     select_okay_gadget[]={
  78.         {RO_Type,OBJECT_GADGET},
  79.         {RO_GadgetType,GADGET_BOOLEAN},
  80.         {RO_GadgetID,SELECT_OKAY},
  81.         {RO_Top,2},
  82.         {RO_TopFine,11},
  83.         {RO_Height,1},
  84.         {RO_HeightFine,6},
  85.         {RO_Width,10},
  86.         {RO_TextNum,STR_OKAY},
  87.         {RO_TextPos,TEXTPOS_CENTER},
  88.         {RO_HighRecess,TRUE},
  89.         {TAG_END,0}},
  90.  
  91.     select_type_gadget[]={
  92.         {RO_Type,OBJECT_GADGET},
  93.         {RO_GadgetType,GADGET_CYCLE},
  94.         {RO_GadgetID,SELECT_SELECTTYPE},
  95.         {RO_Top,2},
  96.         {RO_TopFine,11},
  97.         {RO_Height,1},
  98.         {RO_HeightFine,6},
  99.         {RO_Width,14},
  100.         {RO_WidthFine,20},
  101.         {RO_Left,11},
  102.         {RO_LeftFine,6},
  103.         {RO_HighRecess,TRUE},
  104.         {TAG_END,0}},
  105.  
  106.     select_cancel_gadget[]={
  107.         {RO_Type,OBJECT_GADGET},
  108.         {RO_GadgetType,GADGET_BOOLEAN},
  109.         {RO_GadgetID,SELECT_CANCEL},
  110.         {RO_Top,2},
  111.         {RO_TopFine,11},
  112.         {RO_Height,1},
  113.         {RO_HeightFine,6},
  114.         {RO_Width,10},
  115.         {RO_Left,26},
  116.         {RO_LeftFine,34},
  117.         {RO_TextNum,STR_CANCEL},
  118.         {RO_TextPos,TEXTPOS_CENTER},
  119.         {RO_HighRecess,TRUE},
  120.         {TAG_END,0}},
  121.  
  122.     select_title_text[]={
  123.         {RO_Type,OBJECT_BORDER},
  124.         {RO_BorderType,BORDER_NONE},
  125.         {RO_Width,36},
  126.         {RO_WidthFine,34},
  127.         {RO_TopFine,-1},
  128.         {RO_Height,1},
  129.         {RO_TextNum,STR_ENTER_SELECT_PATTERN},
  130.         {RO_TextPos,TEXTPOS_CENTER},
  131.         {TAG_END,0}},
  132.  
  133.     *select_gadgets[]={
  134.         select_base_gadget,
  135.         select_pattern_gadget,
  136.         select_type_gadget,
  137.         select_okay_gadget,
  138.         select_cancel_gadget,
  139.         NULL};
  140.  
  141. int select_base=0,select_type=0;
  142.  
  143. getselectdata(buffer,selbase)
  144. char **buffer;
  145. int *selbase;
  146. {
  147.     ULONG class;
  148.     USHORT gadgetid;
  149.     struct Window *swindow;
  150.     struct Gadget *gadlist,*sel_type_gad;
  151.     char *select_base_array[3],*select_type_array[3];
  152.     int a,ret=0;
  153.  
  154.     fix_requester(&select_req,globstring[STR_ENTER_SELECT_PATTERN]);
  155.  
  156.     for (a=0;a<3;a++) {
  157.         select_type_array[a]=globstring[STR_SELECT_ALL_ENTRIES+a];
  158.         select_base_array[a]=globstring[STR_SELECT_NAME+a]; 
  159.     }
  160.     strcpy(sel_patternbuf,buffer[select_base]);
  161.  
  162.     if (!(swindow=OpenRequester(&select_req)) ||
  163.         !(gadlist=addreqgadgets(&select_req,select_gadgets,0,NULL)) ||
  164.         !(AddRequesterObject(&select_req,select_title_text))) {
  165.         CloseRequester(&select_req);
  166.         return(0);
  167.     }
  168.     RefreshRequesterObject(&select_req,NULL);
  169.  
  170.     sel_type_gad=gadlist->NextGadget->NextGadget;
  171.     DoCycleGadget(gadlist,swindow,select_base_array,select_base);
  172.     DoCycleGadget(sel_type_gad,swindow,select_type_array,select_type);
  173.  
  174.     ActivateStrGad(gadlist->NextGadget,swindow);
  175.  
  176.     FOREVER {
  177.         while (IMsg=(struct IntuiMessage *)GetMsg(swindow->UserPort)) {
  178.             class=IMsg->Class;
  179.             if (class==IDCMP_GADGETUP)
  180.                 gadgetid=((struct Gadget *) IMsg->IAddress)->GadgetID;
  181.             ReplyMsg((struct Message *) IMsg);
  182.  
  183.             switch (class) {
  184.                 case IDCMP_MOUSEBUTTONS:
  185.                     ActivateStrGad(gadlist->NextGadget,swindow);
  186.                     break;
  187.  
  188.                 case IDCMP_GADGETUP:
  189.                     switch (gadgetid) {
  190.                         case SELECT_SELECTBASE:
  191.                             strcpy(buffer[select_base],sel_patternbuf);
  192.                             if (++select_base>2) select_base=0;
  193.                             DoCycleGadget(gadlist,swindow,select_base_array,select_base);
  194.                             strcpy(sel_patternbuf,buffer[select_base]);
  195.                             RefreshStrGad(gadlist->NextGadget,swindow);
  196.                             ActivateStrGad(gadlist->NextGadget,swindow);
  197.                             break;
  198.                         case SELECT_SELECTTYPE:
  199.                             if (++select_type>2) select_type=0;
  200.                             DoCycleGadget(sel_type_gad,swindow,select_type_array,select_type);
  201.                             ActivateStrGad(gadlist->NextGadget,swindow);
  202.                             break;
  203.                         case SELECT_OKAY:
  204.                             ret=select_type+1;
  205.                         case SELECT_CANCEL:
  206.                             CloseRequester(&select_req);
  207.                             strcpy(buffer[select_base],sel_patternbuf);
  208.                             *selbase=select_base;
  209.                             return(ret);
  210.                     }
  211.                     break;
  212.             }
  213.         }
  214.         Wait(1<<swindow->UserPort->mp_SigBit);
  215.     }
  216. }
  217.